from common.base_page import BasePage
from appium.webdriver.common.appiumby import AppiumBy


class StockTrading(BasePage):
    # 模拟炒股
    imitate_loc = (AppiumBy.XPATH, '//android.widget.ImageView[@bounds="[411,1491][489,1569]"]')
    # 买入
    buy_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_purchase')
    # 输入股票代码
    stockCode_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_stock_search')
    # 点击财富管理
    wealth_loc = (AppiumBy.ID, 'com.jhss.youguu:id/history_item_stockName')
    # 输入购买数量
    inputNum_loc = (AppiumBy.ID, 'com.jhss.youguu:id/et_stock_fund')
    # 点击买入
    clickBuy_loc = (AppiumBy.XPATH, '//android.widget.TextView[@bounds="[24,888][652,968]"]')
    # 点击确定
    determine_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_confirm')
    # 点击撤单
    cancelOrder_loc = (AppiumBy.ID, 'com.jhss.youguu:id/btn_revoke')
    # 获取元素
    getEle_loc = (AppiumBy.XPATH, '//android.widget.TextView[@text="财富管理"]')

    def trading(self, code, num):
        # 模拟炒股
        self.click_ele(self.imitate_loc)
        # 点击买入
        self.click_ele(self.buy_loc)
        # 输入股票代码
        self.send_keys(self.stockCode_loc, code)
        # 点击财富管理
        self.click_ele(self.wealth_loc)
        # 输入买入数量
        self.send_keys(self.inputNum_loc, num)
        # 点击买入
        self.click_ele(self.clickBuy_loc)
        # 点击确定
        self.click_ele(self.determine_loc)
        # 点击撤单
        self.click_ele(self.cancelOrder_loc)
